package com.nageoffer.jobtrain.project.sms;

import com.nageoffer.jobtrain.projects.JobTrainProjectApplication;
import com.nageoffer.jobtrain.projects.config.AliYunSendMessageConfig;
import com.nageoffer.jobtrain.projects.config.MinioConfig;
import com.nageoffer.jobtrain.projects.handler.ContestNotifyWebSocketHandler;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * author：唐晨
 */
@SpringBootTest(classes = JobTrainProjectApplication.class)
public class SmsController {
    @Autowired
    private AliYunSendMessageConfig aliYunSendMessageConfig;

    @Autowired
    private ContestNotifyWebSocketHandler contestNotifyWebSocketHandler;

    @Autowired
    private MinioConfig minioConfig;

    @Test
    public void sendMessage() throws InterruptedException {
        while (true) {
            contestNotifyWebSocketHandler.sendMessage("15678488061",
                    "您报名的 <通知APP12iei> 竞赛将在10分钟后正式开始，请提前做好准备并准时参加，祝您取得优异成绩！");
            Thread.sleep(2000);
        }

    }

    @Test
    public void addDefaultUpLoad() {
        // 图片路径
        String path = "E:\\CompletionProject\\Job-search-training-platform---completed\\jobtrain\\projects\\src\\test\\java\\com\\nageoffer\\jobtrain\\project\\default.png";

        try (InputStream inputStream = new FileInputStream(new File(path))) {
            // 文件名，存储到 MinIO 中的文件名
            String fileName = "default.png";

            // 文件的 MIME 类型
            String contentType = "image/png";

            // 上传文件并获取上传后的 URL
            String fileUrl = minioConfig.uploadFile(fileName, inputStream, contentType);

            // 打印上传后的文件 URL
            System.out.println("Uploaded file URL: " + fileUrl);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void createSql() {
        for (int i = 0; i < 16; i++) {
            String tableName = "t_user_answer_" + i;
            System.out.println("CREATE TABLE `" + tableName + "` (");
            System.out.println("  `id` bigint(20) NOT NULL COMMENT '主键ID',");
            System.out.println("  `question_id` bigint(20) NOT NULL COMMENT 'OJ题目ID',");
            System.out.println("  `phone_number` varchar(20) NOT NULL COMMENT '用户手机号',");
            System.out.println("  `code_type` tinyint(1) NOT NULL COMMENT '代码类型；0：Java；1：C；2：C++；3：Python；4：Go',");
            System.out.println("  `submit_code` text COMMENT '提交的代码',");
            System.out.println("  `pass` tinyint(1) DEFAULT NULL COMMENT '是否通过测试用例',");
            System.out.println("  `execute_result` varchar(1024) DEFAULT NULL COMMENT '执行结果',");
            System.out.println("  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',");
            System.out.println("  `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',");
            System.out.println("  `del_flag` tinyint(1) DEFAULT '0' COMMENT '删除标识',");
            System.out.println("  PRIMARY KEY (`id`)");
            System.out.println(") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户答题表分表" + i + "';");
            System.out.println();
        }
    }
}
